#pragma once
#include "MovingObject.h"
#include "Game.h"

class Augment;
class Weapon;

enum State {IDLE, PATROL, JUMPING, CLOSEIN, ATTACK, DEAD, };

class Enemy : public MovingObject
{
public:
			Enemy();
	virtual ~Enemy();
	enum EnemyType {ENEMY_BAT = 50, ENEMY_ARCHER, ENEMY_BOSS, ENEMY_ELF, ENEMY_GOBLIN, ENEMY_SPIDER, ENEMY_KNIGHT };
	/**********************************************************/
	// Interface:
	//	- virtual functions for children classes to override
	virtual void	Update(float elapsedTime)		override;
	virtual void	Render(void)					override;

//	virtual SGD::Rectangle GetRect(void)	const			override;
	virtual int		GetType(void)	const			override	{ return OBJ_ENEMY; }
	virtual int		GetEnemyType()	const { return ENEMY_BAT; }

//	virtual void	HandleCollision(GameObject* pOther)	override;
	virtual bool DoAttack();
	virtual void Attack();
	virtual void Patrol();
	virtual void MoveLeft(float speed = 100.0f);
	virtual void MoveRight(float speed = 100.0f);

	void StartAnimation(char* anim);

	//accessors
	int GetDamage(void) const { return m_iDamage; }
	int GetRange(void) { return m_iRange; }
	float GetFireRate(void) { return m_iFireRate; }
	bool GetIsRanged(void) { return m_bIsRanged; }
	Augment* GetAugment(void) { return m_aAugment; }
	int GetBulletType(void) { return m_iBulletType; }
	bool GetIsAlive() { return (state != State::DEAD); }
	float RotationToPlayer();

	//mutators
	void SetDamage(int damage) { m_iDamage = damage; }
	void SetRange(int range) { m_iRange = range; }
	void SetFireRate(float firerate) { m_iFireRate = firerate; }
	void SetIsRanged(bool ranged) { m_bIsRanged = ranged; }
	void SetAugment(Augment * augment) { m_aAugment = augment; }
	void SetBulletType(int bullet) { m_iBulletType = bullet; }
	void SetIsAlive(bool alive) { state = State::IDLE; }
	void SetState(State set) { state = State::ATTACK; }

	virtual void EnterIdle();
	virtual void EnterPatrol();
	virtual void EnterJumping();
	virtual void EnterCloseIn();
	virtual void EnterAttack();
	virtual void EnterDead();

	void CharacterCollision(GameObject* pOther);

	float RandPatrolDistance();

private:
	int m_iDamage = 0;
	int m_iRange = 0;
	float m_iFireRate = 0.0f;
	bool m_bIsRanged = false; 
	Augment * m_aAugment = nullptr;
	int m_iBulletType = 0; // Enum in Weapon.h


protected:
	State state = State::IDLE;
	State prevState = State::IDLE;
	bool useGravity = true;
	bool patrolDirectionRight = false;
	bool updating = false;

	SGD::HAudio damageAudio = Game::GetInstance()->GetEnemyDamaged();
};

